package com.zelin.yang.kotlin_demo.Base

import android.content.Context
import android.os.Build
import android.os.Bundle
import android.support.annotation.LayoutRes
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.view.Window
import com.zelin.yang.kotlin_demo.R
import com.zelin.yang.kotlin_demo.util.StatusBarUtils




abstract class BaseActivity : AppCompatActivity() {
    //申明在该模块下的上下文
    lateinit var mContext: Context
    @LayoutRes
    abstract fun getLayoutId():Int
    abstract fun Initview()
    abstract fun initDate()

    override fun onCreate(savedInstanceState: Bundle?) {

        /*LayoutInflaterCompat.setFactory2(LayoutInflater.from(this), object : LayoutInflater.Factory2 {
            override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
                return null
            }

            override fun onCreateView(parent: View, name: String, context: Context, attrs: AttributeSet): View? {
                val delegate = delegate
                val view = delegate.createView(parent, name, context, attrs)

                if (view != null && view is TextView) {
                    view.textSize = 100F
                }
                return view
            }

        })*/
        super.onCreate(savedInstanceState)
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(getLayoutId())
        mContext = this
        Initview()
        initDate()
    }

    /**
     * 沉浸式
     */
    fun changeStatusBarTextColor(isBlack: Boolean){
       if(Build.VERSION.SDK_INT > Build.VERSION_CODES.M){
            StatusBarUtils.immersive(this)
           window.statusBarColor = resources.getColor(R.color.cFFFFFF)
           if (isBlack) {
               //设置状态栏黑色字体
               window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
           }else {
               //恢复状态栏白色字体
               window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
           }
       }
   }
}